<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var canConstruct = function (ransomNote, magazine) {
        let rMap = new Map();
        let mMap = new Map();
        ransomNote.split("").forEach((item) => {
          if (rMap.has(item)) {
            let cur = rMap.get(item);
            rMap.set(item, ++cur);
          } else {
            rMap.set(item, 1);
          }
        });
        magazine.split("").forEach((item) => {
          if (mMap.has(item)) {
            let cur = mMap.get(item);
            mMap.set(item, ++cur);
          } else {
            mMap.set(item, 1);
          }
        });
        console.log(rMap,mMap);
        for (let [rKey,rValue] of rMap) {
            console.log(rKey,rValue);
          if (!mMap.has(rKey) || mMap.get(rKey) < rValue) {
            return false;
          }
        }
        return true;
      };
      console.log(canConstruct("aa","ab")); 
    </script>
  </body>
</html>
